import 'package:flutter/foundation.dart';
import 'package:get/get.dart';
import 'package:laos_mall/app_route.dart';
import 'package:laos_mall/common/utils/storage_util.dart';


class UserData{
  UserData._internal(){
    initConfig();
  }
  factory UserData() => instance;
  static final UserData instance = UserData._internal();
  var isLogin = false.obs;
  var cartNum = 0.obs;
  ///权限
  static var permissionValues = <String,dynamic>{}.obs;
  initConfig(){
    if(StorageUtils().getToken() != null){
      isLogin.value = true;
    }
  }
  startRun(){

  }
  end(){

  }

  bool loginJudge({VoidCallback? callback}){
    if(!isLogin.value){
      Get.toNamed(AppRouter.login);
      return false;
    }
    callback?.call();
    return true;
  }

  logout(){
    StorageUtils().removeKey(StoreKeys.token.toString());
    UserData().isLogin.value = false;

  }

  goToHome(){

  }
}